package com.yylending.remotevideo.anychat;

import com.bairuitech.anychat.AnyChatDefine;
import com.bairuitech.anychat.AnyChatVideoCallEvent;
import com.yyfax.common.CLog;
import com.yylending.remotevideo.AnyChatPresenter;

/**
 * Created by HenryZhang on 2017/4/22.<br>
 * Copyright © 2017 www.yylending.com. All Rights Reserved.<br><br>
 */
public class VideoCallEvent implements AnyChatVideoCallEvent {
	private static final String TAG = "VideoCallEvent";

	private AnyChatPresenter.View mView;

	public VideoCallEvent(AnyChatPresenter.View view) {
		mView = view;
	}

	public void release() {
		mView = null;
	}

	@Override
	public void OnAnyChatVideoCallEvent(int dwEventType, int dwUserId, int dwErrorCode, int dwFlags, int dwParam, String userStr) {
		switch (dwEventType) {
			case AnyChatDefine.BRAC_VIDEOCALL_EVENT_REQUEST:
				CLog.i(TAG, "接收到视频呼叫请求：dwUserId = " + dwUserId);
//				anychat.VideoCallControl(AnyChatDefine.BRAC_VIDEOCALL_EVENT_REPLY, dwUserId, AnyChatDefine.BRAC_ERRORCODE_SUCCESS, 0, 0, "");
				mView.remoteVideoCalling(dwUserId);
				break;
			case AnyChatDefine.BRAC_VIDEOCALL_EVENT_REPLY:
				CLog.i(TAG, "接受视频呼叫请求成功，等待对方反应");
//				BussinessCenter.getBussinessCenter().onVideoCallReply(targetUserId, dwErrorCode, dwFlags, dwParam, userStr);
				if (dwErrorCode == AnyChatDefine.BRAC_ERRORCODE_SUCCESS) {
					CLog.i(TAG, "接受视频呼叫请求成功，对方反应是：成功");
//					dialog = DialogFactory.getDialog(DialogFactory.DIALOGID_CALLING, targetUserId, AgentServiceActivity.this, mApplication);
//					dialog.show();
				} else {
					CLog.i(TAG, "接受视频呼叫请求成功，对方反应是：失败");
//					anychat.VideoCallControl(AnyChatDefine.BRAC_VIDEOCALL_EVENT_FINISH, targetUserId, 0, 0, 0, "");
					mView.callingCanceled();
				}
				break;
			case AnyChatDefine.BRAC_VIDEOCALL_EVENT_START:
				CLog.e(TAG, "会话开始 " + dwUserId + ", " + dwParam);//targetUser, roomId
//				BussinessCenter.getBussinessCenter().onVideoCallStart(targetUserId, dwFlags, dwParam, userStr, mApplication);
				mView.remoteVideoStarting(dwUserId, dwParam);
				break;
			case AnyChatDefine.BRAC_VIDEOCALL_EVENT_FINISH:
				CLog.e(TAG, "会话结束 " + dwUserId + ", " + dwParam);
//				AnyChatCoreSDK.ObjectControl(AnyChatObjectDefine.ANYCHAT_OBJECT_TYPE_AGENT, mApplication.getUserID(), AnyChatObjectDefine.ANYCHAT_AGENT_CTRL_FINISHSERVICE, 0, 0, 0, 0, "");
//				mView.releaseAnyChat();
				mView.callingCanceled();
				break;
		}
	}
}
